<?php

/**
 * 获取当前页面完整URL地址
 */

function get_url($related = 0) {
    $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
    $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
    $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
    return $related ? $relate_url : $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
}
function __get_signature($appid,$appsecret, $noncestr, $acurl, $timestamp)
{
    if(empty($appid) || empty($appsecret)){
        return '';
    }

    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
    $ret = file_get_contents($url);
    $ret = json_decode($ret, TRUE);
    $access_token = $ret['access_token'];


    $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$access_token&type=jsapi";
    $ret = file_get_contents($url);

    $ret = json_decode($ret, TRUE);
    $string1 = "jsapi_ticket=$ret[ticket]&noncestr=$noncestr&timestamp=$timestamp&url=$acurl";

    $signature = sha1( $string1 );
    return $signature;
}

$geturl = get_url();
$cururl = str_replace('guide.php', 'index.html',$geturl);
$pic    = str_replace('guide.php', 'static/logo.png',$geturl);

$appid = 'wxfcc1dbbb2697d6bb';
$appsecret = '1344cea9cf13bf1e6dfb0dff54f0cb69';
$noncestr = uniqid('wx');
$timestamp = time();

$signature = __get_signature($appid, $appsecret, $noncestr, $geturl, $timestamp);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>逍遥掌旅宝，争当火炬手！</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">
    <link href="./static/Wap.css" rel="stylesheet" type="text/css">
    <script src="./static/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="./static/layer.m.js" type="text/javascript"></script><link href="./static/layer.css" type="text/css" rel="styleSheet" id="layermcss">
    <script language="javascript" type="text/javascript">

    </script>
    <style type="text/css">
        * { margin: 0; padding: 0; list-style-type: none; }
        a, img { border: 0; outline: none; }
        body { position: relative; background: url(static/guide.jpg?102) no-repeat center  top ;overflow: hidden;background-size:cover;height: 100vh;width: 100vw}
    </style>
</head>
<body>
<div style="
  position: absolute;
  /* top: 100px; */
  /* left: 104px; */
  font-size: 30px;
  width: 100%;
  text-align: center;
  margin-top: 51%;
  color: rgb(255, 86, 53);">
    已传递<?php echo file_get_contents('total.php');?>次
</div>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
var title='逍遥掌旅宝，争当火炬手！', desc='我是文明旅游火炬手，接棒传递有礼哦！', link='<?php echo $cururl?>',imgUrl='<?php echo $pic?>';
wx.config({
    debug:false,
    appId: '<?php echo $appid?>',
    timestamp: <?php echo $timestamp?>,
    nonceStr: '<?php echo $noncestr?>',
    signature: '<?php echo $signature?>',
    jsApiList: [
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo'
    ]
});
function todoaftershare() {
    window.location.href = "gua.php?add=1";
}
wx.ready(function () {
    wx.onMenuShareAppMessage({
        title: title,
        desc: desc,
        link: link,
        imgUrl: imgUrl,
        success:function(){
            todoaftershare();
        }
    });
    wx.onMenuShareTimeline({
        title: title,
        link: link,
        imgUrl: imgUrl,
        success:function(){
            todoaftershare();
        }
    });
    wx.onMenuShareQQ({
        title: title,
        desc: desc,
        link: link,
        imgUrl: imgUrl,
        success:function(){
            todoaftershare();
        }
    });
    wx.onMenuShareWeibo({
        title: title,
        desc: desc,
        link: link,
        imgUrl: imgUrl,
        success:function(){
            todoaftershare();
        }
    });
});
</script>
</body></html>